home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Special 16
/
AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso
/
pd
/
anwendungen
/
xpk_source
/
test
/
testchunkypack.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-08-27
|
4KB
|
157 lines
#define NAME "testChunkyPack"
#define DISTRIBUTION "(Freeware) "
#define REVISION "0"
/* Programmheader
Name: testChunkyPack
Author: SDI
Distribution: Freeware
Description: tests chunky packing using XpkWrite
Compileropts: -
Linkeropts: -l xpkmaster amiga
1.0 26.08.98 : first version
*/
/* The working method of this program is useful especially for games, as it
is designed mainly to store internal structures part for part into an file.
For correct working you need to use at least xpkmaster.library 4.34! Either
ensure, that this library is installed, or check after opening
if(XpkBase->lib_Version > 4 || XpkBase->lib_Revision >= 34)
{ ... do the work ... }
else
{ ... do some error stuff ... }
*/
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/xpkmaster.h>
#include <exec/memory.h>
#include <exec/execbase.h>
#include "SDI_defines.h"
struct Library *XpkBase = 0;
ULONG DosVersion = 37;
#define CHUNKSIZE 10240
/* NOTE: this chunksize define is the value passed to XpkOpen. It is NOT
the value, which is used, as xpk may change this internally depending on
the packing algorithm, so we need to check xfib->xf_NLen value to get
buffer size! */
/* USER modus cannot be used with this system, as we have no input data
ready, when we start crunching. */
#define PARAM "TO/A,METHOD"
struct Args {
STRPTR to;
STRPTR method;
};
struct BufData {
STRPTR buffer;
ULONG filled;
LONG err;
struct XpkFib *xfib;
};
extern struct DosLibrary *DOSBase;
extern struct ExecBase * SysBase;
LONG SaveData(struct BufData *b, APTR buf, ULONG size);
void main(void)
{
struct Args args = {0,"NUKE"}; /* defaults */
struct RDArgs *rda;
if((rda = ReadArgs(PARAM, (LONG *) &args, 0)))
{
if((XpkBase = OpenLibrary(XPKNAME, 4)))
{
struct BufData b;
LONG err;
if(!(err = XpkOpenTags(&b.xfib, XPK_PackMethod, args.method,
XPK_OutName, args.to, XPK_ChunkSize, CHUNKSIZE, XPK_Preferences, 0,
TAG_DONE)))
{
if((b.buffer = (STRPTR) AllocVec(b.xfib->xf_NLen, MEMF_ANY)))
{
b.filled = 0;
b.err = 0;
/* this is a test, saving some really useless stuff */
{
ULONG a = *((ULONG *)(((STRPTR) 0x1000000)-20));
SaveData(&b, "IDXTCP10", 8); /* an ID value to detect our data */
SaveData(&b, "This is the DOSBase:", 21);
SaveData(&b, DOSBase, sizeof(struct DosLibrary));
SaveData(&b, "This is the SysBase:", 21);
SaveData(&b, SysBase, sizeof(struct ExecBase));
Printf("Storing kickrom, this will take some time\n");
SaveData(&b, "This is the kickrom:", 21);
SaveData(&b, ((STRPTR) 0x1000000)-a, a);
if(err = SaveData(&b, 0, 0))
XpkPrintFault(err, 0);
}
FreeVec(b.buffer);
}
XpkClose(b.xfib);
}
else
XpkPrintFault(err, 0);
CloseLibrary(XpkBase);
}
FreeArgs(rda);
}
}
/* Call this function for every data to store, calling it with size zero
means all data is done and the last stuff should be stored in file.
This function uses a delayed error report, so we need not check every call.
SaveData does nothing except returning the error again, when an error
occured a call before. */
LONG SaveData(struct BufData *b, APTR buf, ULONG size)
{
LONG i;
if(!size && !b->err) /* end the packed file */
{
if(b->filled)
{
i = XpkWrite(b->xfib, b->buffer, b->filled);
b->filled = 0;
return i;
}
else
return 0;
}
while(size && !b->err)
{
if((i = b->xfib->xf_NLen - b->filled) > size)
i = size;
CopyMem(buf, b->buffer+b->filled, i);
b->filled += i;
size -= i;
buf = ((STRPTR) buf) + i;
if(b->filled == b->xfib->xf_NLen)
{
b->err = XpkWrite(b->xfib, b->buffer, b->filled);
b->filled = 0;
}
}
return b->err;
}